import mx.events.EventDispatcher;

import org.molamil.acto.core.Dispatcher;
import org.molamil.acto.core.EventConstants;
import org.molamil.acto.mc.AbstractMcWrapper;
import org.molamil.acto.mc.InvalidLcStateError;
import org.molamil.acto.mc.McNotSetError;

/**
 * <code>AbstractMcWrapper</code> that keeps track of the <code>MovieClip</code>'s LyfeCycle. 
 * The <code>state</code> can hold these values:
 * <ul>
 * 	<li><code>"IN"</code>: The MC is being built, animated in.</li>
 * 	<li><code>"ON"</code>: The MC has been built, default state when stand by.</li>
 * 	<li><code>"OUT"</code>: The MC is being unbuilt, animated out.</li>
 * 	<li><code>"OFF"</code>: The MC has been unbuilt or hasn't been built yet.</li>
 * </ul>
 *<br />
 * Dispatches:
 * <ul>
 * 	<li><code>onMcStateChange</code>: The <code>state</code> of the MovieClip wrapper has changed.</li>
 * </ul>
 *
 * @author Jorge Hernandez
 */
class org.molamil.acto.mc.mcw.LcMcWrapper extends AbstractMcWrapper implements Dispatcher {
	
	
	// Constants
	
	/**
	 * The MC is being built, animated in.
	 * With value <code>IN</code>
	 */
	public static function get STATE_IN():String { return "IN"; }
	
	/**
	 * The MC has been built, default state when stand by.
	 * With value <code>ON</code>
	 */
	public static function get STATE_ON():String { return "ON"; }
	
	/**
	 * The MC is being unbuilt, animated out.
	 * With value <code>OUT</code>
	 */
	public static function get STATE_OUT():String { return "OUT"; }
	
	/**
	 * The MC has been unbuilt or hasn't been built yet.
	 * With value <code>OFF</code>
	 */
	public static function get STATE_OFF():String { return "OFF"; }
	
	
	// Properties
	
	private var _state:String;
	
	
	// Constructor
	
	/**
	 * Sets state to <code>"OFF"</code>.
	 */
	public function LcMcWrapper() {
		EventDispatcher.initialize(this);
		_state = STATE_OFF;
	}
	
	
	// Functions
	
	public function dispatchEvent(eventObj:Object):Void {}
	public function addEventListener(event:String, handler):Void {}
	public function removeEventListener(event:String, handler):Void {}
	
	private function changeState():Void {
		var eventObject:Object = {target: this, type: EventConstants.MC_STATE_CHANGE, state: state};
		dispatchEvent(eventObject);
	}
	
	
	// Getter/Setter
	
	/**
	 * Current state of the MC:
	 * <ul>
	 * 	<li><code>"IN"</code>: The MC is being built, animated in.</li>
	 * 	<li><code>"ON"</code>: The MC has been built, default state when stand by.</li>
	 * 	<li><code>"OUT"</code>: The MC is being unbuilt, animated out.</li>
	 * 	<li><code>"OFF"</code>: The MC has been unbuilt or hasn't been built yet.</li>
	 * </ul>
	 */
	public function get state():String {
		return _state;
	}
	
	public function set state(state:String):Void {
		if (_mc == null)
			throw new McNotSetError();
		state = state.toUpperCase();
		if (state != STATE_IN && state != STATE_ON && state != STATE_OUT && state != STATE_OFF)
			throw new InvalidLcStateError();
		if (state != _state) {
			_state = state;
			changeState();
		}
	}
	
	
}